package cn.harry.modular.ai.service.impl;

import cn.harry.common.exception.ApiException;
import cn.harry.modular.system.enums.StatusEnums;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.harry.modular.ai.mapper.ChatModelMapper;
import cn.harry.modular.ai.service.ChatModelService;
import cn.harry.modular.ai.domain.ChatModel;


import static cn.harry.modular.ai.enums.ErrorCodeConstants.*;

/**
 * AI 聊天模型服务实现类
 *
 * @author harry
 * @公众号 Harry技术
 */
@Service
@RequiredArgsConstructor
public class ChatModelServiceImpl extends ServiceImpl<ChatModelMapper, ChatModel> implements ChatModelService {

    @Override
    public ChatModel validateChatModel(Long modelId) {
        ChatModel model = validateChatModelExists(modelId);
        if (StatusEnums.DISABLE.getKey().equals(model.getStatus().toString())) {
            throw new ApiException(CHAT_MODEL_DISABLE);
        }
        return model;
    }

    public ChatModel validateChatModelExists(Long modelId) {
        ChatModel chatModel = getById(modelId);
        if (chatModel == null) {
            throw new ApiException(CHAT_MODEL_NOT_EXISTS);
        }
        return chatModel;
    }
}
